from random import choice

def get_winning_ticket(possibilities):
    """生成中奖号码"""
    prizes = []

    while len(prizes) < 4:
        prize = choice(possibilities)
        if prize in prizes:
            continue
        else:
            prizes.append(prize)
    return prizes

def chick_ticket(play_ticket,winning_ticket):
    """检查玩家的彩票号码是否与中奖号码一致"""
    for element in ticket:
        if element not in winning_ticket:
            return False

    return True # 中奖了

def make_random_ticket(possibilities):
    """生成随机彩票"""
    ticket = []
    while len(ticket) < 4:
        num = choice(possibilities)
        if num not in ticket:
            ticket.append(num)
        else:
            continue
    return ticket

possibilities = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 'a', 'b', 'c', 'd', 'e']
prizes = get_winning_ticket(possibilities)

plays = 0
won = False

# 为避免程序执行时间太长，设置最多随机生成多少张彩票
max_tries = 1_000_000

while not won:
    ticket = make_random_ticket(possibilities)
    won = chick_ticket(ticket,prizes)
    plays += 1
    if plays == max_tries:
        break

if won:
    print("We have a winning ticket!")
    print(f"Your ticket: {ticket}")
    print(f"Winning ticket: {prizes}")
    print(f"It only took {plays} tries to win!")

else:
 print(f"Tried {plays} times, without pulling a winner. :(")
 print(f"Your ticket: {ticket}")
 print(f"Winning ticket: {prizes}")